{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from beakerx import *\n",
    "Plot(title=\"We Will Control the Title\",\n",
    "     xLabel=\"Horizontal\",\n",
    "     yLabel=\"Vertical\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Lines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot1 = Plot()\n",
    "plot1.add(Line(x=[0, 1, 2, 3, 4, 5], y=[0, 1, 6, 5, 2, 8]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Line properties"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot2  = Plot(title= \"Setting line properties\")\n",
    "ys = [0, 1, 6, 5, 2, 8]\n",
    "ys2 = [0, 2, 7, 6, 3, 8]\n",
    "plot2.add(Line(y= ys, width= 10, color= Color.red))\n",
    "plot2.add(Line(y= ys, width= 3, color= Color.yellow))\n",
    "plot2.add(Line(y= ys, width= 4, color= Color(33, 87, 141), style= StrokeType.DASH, interpolation= 0))\n",
    "plot2.add(Line(y= ys2, width= 2, color= Color(212, 57, 59), style= StrokeType.DOT))\n",
    "plot2.add(Line(y= [5, 0], x= [0, 5], style= StrokeType.LONGDASH))\n",
    "plot2.add(Line(y= [4, 0], x= [0, 5], style= StrokeType.DASHDOT))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Stems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot3 = Plot()\n",
    "y1 = [1.5, 1, 6, 5, 2, 8]\n",
    "cs = [Color.black, Color.red, Color.gray, Color.green, Color.blue, Color.pink]\n",
    "ss = [StrokeType.SOLID, StrokeType.SOLID, StrokeType.DASH, StrokeType.DOT, StrokeType.DASHDOT, StrokeType.LONGDASH]\n",
    "plot3.add(Stems(y= y1, color= cs, style= ss, width= 5))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Base of Stems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot4 = Plot(title= \"Setting the base of Stems\")\n",
    "ys = [3, 5, 2, 3, 7]\n",
    "y2s = [2.5, -1.0, 3.5, 2.0, 3.0]\n",
    "plot4.add(Stems(y= ys, width= 2, base= y2s))\n",
    "plot4.add(Points(y= ys))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot5 = Plot(title= \"Bars\")\n",
    "cs = [Color(255, 0, 0, 128)] * 5 \n",
    "cs[3] = Color.red \n",
    "plot5.add(Bars(x= [1, 2, 3, 4, 5], y= [3, 5, 2, 3, 7], color= cs, outlineColor= Color.black, width= 0.3))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Points"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot6 = Plot(title= \"Changing Point Size, Color, Shape\")\n",
    "plot6.add(Points(y= [6, 7, 12, 11, 8, 14]))\n",
    "plot6.add(Points(y= [4, 5, 10, 9, 6, 12], shape= ShapeType.CIRCLE))\n",
    "plot6.add(Points(y= [2, 3, 8, 7, 4, 10], size= 8.0, shape= ShapeType.DIAMOND))\n",
    "plot6.add(Points(y= [0, 1, 6, 5, 2, 8], size= 12.0, color= Color.orange, outlineColor= Color.red))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot7 = Plot(title= \"Changing point properties with list\")\n",
    "cs = [Color.black, Color.red, Color.orange, Color.green, Color.blue, Color.pink]\n",
    "ss = [6.0, 9.0, 12.0, 15.0, 18.0, 21.0]\n",
    "fs = [False, False, False, True, False, False]\n",
    "plot7.add([Points(y= [5] * 6, size= 12.0, color= cs),\n",
    "           Points(y= [4] * 6, size= 12.0, color= Color.gray, outlineColor= cs),\n",
    "           Points(y= [3] * 6, size= ss, color= Color.red),\n",
    "           Points(y= [2] * 6, size= 12.0, color= Color.black, fill= fs, outlineColor= Color.black)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Areas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot8 = Plot()\n",
    "y = [3, 5, 2, 3]\n",
    "x0 = [0, 1, 2, 3]\n",
    "x1 = [3, 4, 5, 8]\n",
    "plot8.add(Area(x= x0, y= y))\n",
    "plot8.add(Area(x= x1, y= y, color= Color(128, 128, 128, 50), interpolation= 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot9 = Plot()\n",
    "plot9.add(Line(y= [3, 6, 12, 24], displayName= \"Median\"))\n",
    "plot9.add(Area(y= [4, 8, 16, 32], base= [2, 4, 8, 16],\n",
    "              color= Color(255, 0, 0, 50), displayName= \"Q1 to Q3\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# XYStacker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "y1 = [1,5,3,2,3]\n",
    "y2 = [7,2,4,1,3]\n",
    "plot10 = Plot(title= 'Plot with XYStacker', initHeight= 200)\n",
    "a1 = Area(y= y1, displayName= 'y1')\n",
    "a2 = Area(y= y2, displayName= 'y2')\n",
    "stacker = XYStacker()\n",
    "plot10.add(stacker.stack([a1, a2]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ConstantLines and ConstantBands"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot11 = Plot()\n",
    "plot11.add(Line(y= [-1, 1]))\n",
    "plot11.add(ConstantLine(x= 0.65, style= StrokeType.DOT, color= Color.blue))\n",
    "plot11.add(ConstantLine(y= 0.1, style= StrokeType.DASHDOT, color= Color.blue))\n",
    "plot11.add(ConstantLine(x= 0.3, y= 0.4, color= Color.gray, width= 5, showLabel= True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot12 = Plot() \n",
    "plot12.add(Line(y= [-3, 1, 3, 4, 5]))\n",
    "plot12.add(ConstantBand(x= [1, 2], y= [1, 3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot13 = Plot() \n",
    "plot13.add(Line(x= [-3, 1, 2, 4, 5], y= [4, 2, 6, 1, 5]))\n",
    "plot13.add(ConstantBand(x= [-3, 1], color= Color(128, 128, 128, 50)))\n",
    "plot13.add(ConstantBand(x= [1, 2]))\n",
    "plot13.add(ConstantBand(x= [4, 6]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from beakerx.plot import Text as BeakerxText\n",
    "plot14 = Plot()\n",
    "xs = list(range(1, 11))\n",
    "ys = [8.6, 6.1, 7.4, 2.5, 0.4, 0.0, 0.5, 1.7, 8.4, 1]\n",
    "label = ['', 'min', 'max', 'falling', 'falling', 'min', 'rising', 'rising', 'max', '']          \n",
    "for i in range(1, 9):\n",
    "    plot14.add(BeakerxText(x= xs[i], y= ys[i], text= label[i],  pointerAngle= -i/3.0))\n",
    "    \n",
    "plot14.add(Line(x= xs, y= ys))\n",
    "plot14.add(Points(x= xs, y= ys))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Crosshair"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ch = Crosshair(color= Color(255, 128, 5), width= 2, style= StrokeType.DOT)\n",
    "plot15 = Plot(crosshair= ch, omitCheckboxes= True, legendLayout= LegendLayout.HORIZONTAL)\n",
    "x = [1, 4, 6, 8, 10]\n",
    "y = [3, 6, 4, 5, 9]\n",
    "plot15.add(Line(displayName= \"Line\", x= x, y= y, width= 3))\n",
    "plot15.add(Bars(displayName= \"Bar\", x= range(1, 11), y= [2, 2, 4, 4, 2, 2, 0, 2, 2, 4], width= 0.5))\n",
    "plot15.add(Points(x= x, y= y, size= 10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot15.setLegendPosition(LegendPosition.RIGHT)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# SimpleTimePlot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "tableRows = pd.read_csv('../../../doc/resources/data/interest-rates.csv')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "SimpleTimePlot(tableRows, [\"y1\", \"y10\"], # column names,\n",
    "                   timeColumn=\"time\", # time is default value for a timeColumn,\n",
    "                   displayNames=[\"1 Year\", \"10 Year\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Milliseconds resolution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "\n",
    "millis = 1507541201624;\n",
    "hour = round(1000 * 60 * 60);\n",
    "xs = [];\n",
    "ys = [];\n",
    "for i in range(11):\n",
    "    xs.append(millis + hour * i);\n",
    "    ys.append(i);\n",
    "\n",
    "plot = TimePlot(timeZone=\"America/New_York\")\n",
    "# list of milliseconds\n",
    "plot.add(Points(x=xs, y=ys))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Nanoseconds resolution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "\n",
    "millis = 1507541201624;\n",
    "nanos  = millis * 1000 * 1000\n",
    "xs = []\n",
    "ys = []\n",
    "for i in range(11):\n",
    "    xs.append(nanos + 7 * i)\n",
    "    ys.append(i);\n",
    "\n",
    "np = NanoPlot()\n",
    "np.add(Points(x=xs, y=ys))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Second Y Axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sp = Plot()\n",
    "sp.add(YAxis(label= \"Test y axis\"))\n",
    "sp.add(Line(\n",
    "        x=pd.Series([10, 20, 30, 40, 50, 60, 70]), \n",
    "        y=pd.Series([0, 60, 10, 50, 20, 40, 30])))\n",
    "sp.add(Line(\n",
    "        x=pd.Series([5, 15, 25, 35, 45, 55, 65]), \n",
    "        y=pd.Series([5, 65, 15, 55, 25, 45, 35]), yAxis= \"Test y axis\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Logarithmic Scale"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "points = 100;\n",
    "xs = [];\n",
    "for i in range(0, points):\n",
    "  xs.append(i)\n",
    "\n",
    "cplot = CombinedPlot(xLabel= \"CombinedPlot\");\n",
    "\n",
    "linearPlot = Plot(title= \"Linear x, Linear y\");\n",
    "linearPlot.add(Line(x= xs, y= xs));\n",
    "cplot.add(linearPlot, 3);\n",
    "\n",
    "logYPlot = Plot(logY= True, logX=False, title= \"Linear x, Log y\");\n",
    "logYPlot.add(Line(x= xs, y= xs));\n",
    "cplot.add(logYPlot, 3);\n",
    "\n",
    "logYPlot = Plot(logY= False, logX=True, title= \"Log x, Linear y\");\n",
    "logYPlot.add(Line(x= xs, y= xs));\n",
    "cplot.add(logYPlot, 3);\n",
    "\n",
    "cplot\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": false,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": false,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
